package com.gmrz.webauthn.protocol.v1.schema;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class Version
        implements Comparable<Version>
{
    @Expose
    @SerializedName("major")
    private Long major = null;
    @Expose
    @SerializedName("minor")
    private Long minor = null;

    public Version(Long major, Long minor)
    {
        this.major = major;
        this.minor = minor;
    }

    public Long getMajor()
    {
        return this.major;
    }

    public Long getMinor()
    {
        return this.minor;
    }

    public void setMajor(Long major)
    {
        this.major = major;
    }

    public void setMinor(Long minor)
    {
        this.minor = minor;
    }

    public int compareTo(Version that)
    {
        if (equals(that)) {
            return 0;
        }
        int result = compareLongs(this.major, that.major);
        if (result != 0) {
            return result;
        }
        return compareLongs(this.minor, that.minor);
    }

    private int compareLongs(Long a, Long b)
    {
        if ((a == null) && (b == null)) {
            return 0;
        }
        if (((a == null ? 1 : 0) ^ (b == null ? 1 : 0)) != 0) {
            return a == null ? -1 : 1;
        }
        return a.compareTo(b);
    }

    public int hashCode()
    {
        int prime = 31;
        int result = 1;
        result = 31 * result + (this.major == null ? 0 : this.major.hashCode());
        result = 31 * result + (this.minor == null ? 0 : this.minor.hashCode());
        return result;
    }

    public boolean equals(Object obj)
    {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Version other = (Version)obj;
        if (this.major == null)
        {
            if (other.major != null) {
                return false;
            }
        }
        else if (!this.major.equals(other.major)) {
            return false;
        }
        if (this.minor == null)
        {
            if (other.minor != null) {
                return false;
            }
        }
        else if (!this.minor.equals(other.minor)) {
            return false;
        }
        return true;
    }

    public Version withVersion(long major, long minor)
    {
        this.major = Long.valueOf(major);
        this.minor = Long.valueOf(minor);
        return this;
    }

    public String toString()
    {
        return "{major:" + this.major + ", minor:" + this.minor + "}";
    }
}

